"""drf_路由 URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, re_path
from app01 import views
# 第一步 先导入routers模块
from rest_framework import routers
# 第二步 有两个类, 生成的路由更多
# routers.DefaultRouter
router = routers.SimpleRouter()
# router = routers.DefaultRouter()
# 第三步 注册
# router.register('前缀,不需要加斜杠', '继承值ModelViewSer的视图类', '别名(reverse反向解析来用)')
router.register('books', views.BookViewSet)

# 第四步
# router.urls 自动生成的路由
print(router.urls)
# [<URLPattern '^books/$' [name='book-list']>, <URLPattern '^books/(?P<pk>[^/.]+)/$' [name='book-detail']>]

urlpatterns = [
    path('admin/', admin.site.urls),
    path('login/', views.LoginView.as_view()),
    path('test/', views.TestView.as_view()),
    # path('books/', views.BookViewSet.as_view(actions={'get': 'list', 'post': 'create'})),
    # re_path(r'^books/(?P<pk>\d+)', views.BookViewSet.as_view(actions={'get': 'retrieve', 'put': 'update', 'delete': 'destroy'})),
]

urlpatterns += router.urls